package com.huashi.dealer.modular.business.order.param;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.huashi.dealer.modular.business.order.enums.AuditStatusEnum;
import com.huashi.dealer.modular.business.order.enums.DeliveryStatusEnum;
import com.huashi.dealer.modular.business.order.enums.OrderStatusEnum;
import com.huashi.dealer.modular.business.order.enums.PayStatusEnum;
import com.huashi.dealer.modular.business.order.enums.ReceiptStatusEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.time.LocalDate;

/**
 * Store端订单列表查询参数
 * 使用枚举值来区分不同类型的订单
 *
 * @author 谭陈强
 * @since 2025-08-15
 */
@Data
@Schema(description = "订单列表查询参数")
public class StoreOrderListParam {

    @Schema(description = "搜索关键词（订单号、用户昵称、真实姓名）")
    private String search;

    @Schema(description = "开始时间")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private LocalDate startTime;

    @Schema(description = "结束时间")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private LocalDate endTime;

    @Schema(description = "审核状态筛选")
    private Integer auditStatus;

    @Schema(description = "支付类型筛选")
    private Integer payType;

    @Schema(description = "配送方式筛选")
    private Integer deliveryType;

    @Schema(description = "自提门店ID")
    private Long extractShopId;

    @Schema(description = "用户ID")
    private Long userId;

    // ========== 订单类型筛选（使用枚举值） ==========
    
    @Schema(description = "订单状态筛选 - 使用OrderStatusEnum的值")
    private Integer orderStatus;

    @Schema(description = "支付状态筛选 - 使用PayStatusEnum的值")
    private Integer payStatus;

    @Schema(description = "发货状态筛选 - 使用DeliveryStatusEnum的值")
    private Integer deliveryStatus;

    @Schema(description = "收货状态筛选 - 使用ReceiptStatusEnum的值")
    private Integer receiptStatus;

    // ========== 预定义的订单类型常量 ==========
    
    /**
     * 待发货订单：已付款，未发货，已审核，订单状态正常
     */
    public static final int TYPE_DELIVERY = 1;
    
    /**
     * 待审核订单：订单状态正常，审核状态为初审或复审
     */
    public static final int TYPE_AUDIT = 2;
    
    /**
     * 待收货订单：已付款，已发货，已审核，订单状态正常
     */
    public static final int TYPE_RECEIPT = 3;
    
    /**
     * 待付款订单：未付款，订单状态正常
     */
    public static final int TYPE_PAY = 4;
    
    /**
     * 已完成订单：已收货，订单状态正常
     */
    public static final int TYPE_COMPLETE = 5;
    
    /**
     * 已取消订单：订单状态为已取消
     */
    public static final int TYPE_CANCEL = 6;

    @Schema(description = "订单类型筛选 - 使用预定义的类型常量")
    private Integer orderType;

    // ========== 便捷方法 ==========
    
    /**
     * 设置待发货订单筛选条件
     */
    public void setDeliveryType() {
        this.orderType = TYPE_DELIVERY;
        this.payStatus = PayStatusEnum.SUCCESS.getValue();
        this.deliveryStatus = DeliveryStatusEnum.PENDING.getValue();
        this.orderStatus = OrderStatusEnum.PROCESSING.getValue();
        this.auditStatus = AuditStatusEnum.APPROVED.getValue();
    }

    /**
     * 设置待审核订单筛选条件
     */
    public void setAuditType() {
        this.orderType = TYPE_AUDIT;
        this.orderStatus = OrderStatusEnum.PROCESSING.getValue();
        // 审核状态为待审核或初审待审核
        // 这里可以根据具体业务逻辑设置
    }

    /**
     * 设置待收货订单筛选条件
     */
    public void setReceiptType() {
        this.orderType = TYPE_RECEIPT;
        this.payStatus = PayStatusEnum.SUCCESS.getValue();
        this.deliveryStatus = DeliveryStatusEnum.DELIVERED.getValue();
        this.orderStatus = OrderStatusEnum.PROCESSING.getValue();
        this.auditStatus = AuditStatusEnum.APPROVED.getValue();
        this.receiptStatus = ReceiptStatusEnum.PENDING.getValue();
    }

    /**
     * 设置待付款订单筛选条件
     */
    public void setPayType() {
        this.orderType = TYPE_PAY;
        this.payStatus = PayStatusEnum.PENDING.getValue();
        this.orderStatus = OrderStatusEnum.PROCESSING.getValue();
    }

    /**
     * 设置已完成订单筛选条件
     */
    public void setCompleteType() {
        this.orderType = TYPE_COMPLETE;
        this.receiptStatus = ReceiptStatusEnum.RECEIVED.getValue();
        this.orderStatus = OrderStatusEnum.PROCESSING.getValue();
    }

    /**
     * 设置已取消订单筛选条件
     */
    public void setCancelType() {
        this.orderType = TYPE_CANCEL;
        this.orderStatus = OrderStatusEnum.CANCELLED.getValue();
    }
}
